package com.edu.juc.threadPool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest2 {
    // 自定义线程池
    public static void main(String[] args) {
        ThreadPoolExecutor executor =
                new ThreadPoolExecutor(
                        2,
                        5,
                        2L,
                        TimeUnit.MINUTES,
                        new ArrayBlockingQueue<>(3),
                        new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 7; i++) {
            int finalI = i;
            executor.execute(() -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println(Thread.currentThread().getName() + "::" + finalI);
            });
        }

        executor.shutdown();

    }
}
